/*
* Main.fx
 *
 * Created on 2009-02-27, 10:41:39
 */

package pl.koziolekweb.prezentacja4developers;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.scene.Group;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import javafx.stage.StageStyle;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.scene.shape.Polyline;
import javafx.scene.shape.Line;

def currentWidth: Float = bind this.stage.width;
def currentHeight: Float = bind this.stage.height;

var normalFont: Font = Font{
    size: 0
};
var titleFont: Font = Font{
    size: 0
};
var smallFont: Font = Font{
    size: 0
};

var jAppletY: Number;
var jMsY: Number;
var jFXDesktopY: Number;
var jFXTVY: Number;

Timeline{
    repeatCount: 1
    keyFrames: [
        KeyFrame{
            canSkip: false
            action: function():Void{
                var fm: FontManager = new FontManager();
                normalFont = fm.getNormalFont();
                titleFont = fm.getBigFont();
                smallFont = fm.getSmallFont();
                jAppletY = 0.15 * currentHeight;
                jMsY = 0.65 * currentHeight;
                jFXDesktopY = 0.15 * currentHeight;
                jFXTVY = 0.65 * currentHeight;
            }
            time: 1s
        }
    ]
}.play();

var titleBar: TitleBar= TitleBar{
    currentHeight: bind this.currentHeight
    currentWidth: bind this.currentWidth
    title: "JavaFX w dokładnie 5 minut"
    font: bind titleFont
    image: "{__DIR__}logo4Developers.jpg"

}

var timer: Timer= Timer{
    currentHeight: bind this.currentHeight
    currentWidth: bind this.currentWidth
    currentTime: 300
    font: bind smallFont
}
var faE = false;
function firstAnim():Void{
    if(not faE){
        Timeline{
            repeatCount: 1
            keyFrames: [
            at(3s){jAppletY =>
                0.40 * currentHeight}
            at(3s){jMsY =>
                0.40 * currentHeight}
            at(3s){jAppletOpacity => 0}
            at(4s){jFxOpacity => 1}
                KeyFrame{
                    canSkip: false
                    action: function():Void{
                        faE = true;
                    }
                    time: 4s
                }
            ]
        }.play();
    
    }
}

var saE = false;
function secondAnim():Void{
    if(not saE){
        Timeline{
            repeatCount: 1
            keyFrames: [
            at(4s){jElementsOpacity => 1}
                KeyFrame{
                    canSkip: false
                    action: function():Void{
                        saE = true;
                    }
                    time: 4s
                }
            ]
        }.play();
    }
}
var fdaE = false;
function thirdAnim():Void{
    if(not fdaE){
        Timeline{
            repeatCount: 1
            keyFrames: [
            at(4s){jElementsOpacity => 0}
            at(4s){jFxOpacity=> 0}
                KeyFrame{
                    canSkip: false
                    action: function():Void{
                        fdaE = true;
                    }
                    time: 4s
                }
            at(5s){ jNameOpacity => 1}
            ]
        }.play();
    }
}

var jAppletOpacity: Float = 1;
var jApplet = Group{
    opacity: bind jAppletOpacity
    content: [
        Rectangle {
            x: bind 0.03 * currentWidth;
            y: bind jAppletY
            width: bind 0.2 * currentWidth,
            height: bind 0.2 * currentHeight
            fill: Color.TRANSPARENT
            stroke: Color.BLUE
            strokeWidth: bind 0.008 * currentHeight
            arcWidth: bind 0.01 * currentWidth
            arcHeight: bind 0.01 * currentWidth
        }
        Text {
            font: bind normalFont
            x: bind 0.045 * currentWidth,
            y: bind jAppletY + (0.11 * currentHeight)
            content: "JApplet"
        }
    ]
    onMouseClicked: function( e: MouseEvent ):Void {
        firstAnim();
    }
}
var jMe = Group{
    opacity: bind jAppletOpacity
    content: [
        Rectangle {
            x: bind 0.03 * currentWidth,
            y: bind 0.40 * currentHeight
            width: bind 0.2 * currentWidth,
            height: bind 0.2 * currentHeight
            fill: Color.TRANSPARENT
            stroke: Color.BLUE
            strokeWidth: bind 0.008 * currentHeight
            arcWidth: bind 0.01 * currentWidth
            arcHeight: bind 0.01 * currentWidth
        }
        Text {
            font: bind normalFont
            x: bind 0.045 * currentWidth,
            y: bind 0.510 * currentHeight
            content: "J2ME"
        }
    ]
    onMouseClicked: function( e: MouseEvent ):Void {
        firstAnim();
    }
}
var jMf = Group{
    opacity: bind jAppletOpacity
    content: [
        Rectangle {
            x: bind 0.03 * currentWidth,
            y: bind jMsY
            width: bind 0.2 * currentWidth,
            height: bind 0.2 * currentHeight
            fill: Color.TRANSPARENT
            stroke: Color.BLUE
            strokeWidth: bind 0.008 * currentHeight
            arcWidth: bind 0.01 * currentWidth
            arcHeight: bind 0.01 * currentWidth
        }
        Text {
            font: bind normalFont
            x: bind 0.045 * currentWidth,
            y: bind jMsY + (0.11 * currentHeight)
            content: "JMF"
        }
    ]
    onMouseClicked: function( e: MouseEvent ):Void {
        firstAnim();
    }
}

var jFxOpacity: Float=0;
var jFx = Group{
    opacity: bind jFxOpacity
    content: [
        Rectangle {
            x: bind 0.03 * currentWidth,
            y: bind 0.40 * currentHeight
            width: bind 0.2 * currentWidth,
            height: bind 0.2 * currentHeight
            fill: Color.TRANSPARENT
            stroke: Color.BLUE
            strokeWidth: bind 0.008 * currentHeight
            arcWidth: bind 0.01 * currentWidth
            arcHeight: bind 0.01 * currentWidth
        }
        Text {
            font: bind normalFont
            x: bind 0.045 * currentWidth,
            y: bind 0.510 * currentHeight
            content: "JavaFX"
        }
    ]
    onMouseClicked: function( e: MouseEvent ):Void {
        if(faE)
        secondAnim();
    }
}

var jElementsOpacity: Float=0;
var jFXDesktop = Group{
    opacity: bind jElementsOpacity
    content: [
        Line {
            startX: bind 0.25 * currentWidth,
            startY: bind 0.50 * currentHeight
            endX: bind 0.4 * currentWidth,
            endY: bind jFXDesktopY + 0.1 * currentHeight
            strokeWidth: 5
            stroke: Color.RED
        }
        Rectangle {
            x: bind 0.43 * currentWidth,
            y: bind jFXDesktopY
            width: bind 0.2 * currentWidth,
            height: bind 0.2 * currentHeight
            fill: Color.TRANSPARENT
            stroke: Color.BLUE
            strokeWidth: bind 0.008 * currentHeight
            arcWidth: bind 0.01 * currentWidth
            arcHeight: bind 0.01 * currentWidth
        }
        Text {
            font: bind normalFont
            x: bind 0.45 * currentWidth,
            y: bind jFXDesktopY + (0.05 * currentHeight)
            content: "JavaFX\nDesktop"
        }
    ]
    onMouseClicked: function( e: MouseEvent ):Void {
        if(saE)
        thirdAnim();
    }
};
var jFXMobile = Group{
    opacity: bind jElementsOpacity
    content: [
        Line {
            startX: bind 0.25 * currentWidth,
            startY: bind 0.50 * currentHeight
            endX: bind 0.4 * currentWidth,
            endY: bind 0.50 * currentHeight
            strokeWidth: 5
            stroke: Color.RED
        }
        Rectangle {
            x: bind 0.43 * currentWidth,
            y: bind 0.40 * currentHeight
            width: bind 0.2 * currentWidth,
            height: bind 0.2 * currentHeight
            fill: Color.TRANSPARENT
            stroke: Color.BLUE
            strokeWidth: bind 0.008 * currentHeight
            arcWidth: bind 0.01 * currentWidth
            arcHeight: bind 0.01 * currentWidth
        }
        Text {
            font: bind normalFont
            x: bind 0.45 * currentWidth,
            y: bind (0.40 + 0.05) * currentHeight
            content: "JavaFX\nMobile"
        }
    ]
    onMouseClicked: function( e: MouseEvent ):Void {
        if(saE)
        thirdAnim();
    }
};
var jFXTV = Group{
    opacity: bind jElementsOpacity
    content: [
        Line {
            startX: bind 0.25 * currentWidth,
            startY: bind 0.50 * currentHeight
            endX: bind 0.4 * currentWidth,
            endY: bind jFXTVY + 0.1 * currentHeight
            strokeWidth: 5
            stroke: Color.RED
        }
        Rectangle {
            x: bind 0.43 * currentWidth,
            y: bind jFXTVY
            width: bind 0.2 * currentWidth,
            height: bind 0.2 * currentHeight
            fill: Color.TRANSPARENT
            stroke: Color.BLUE
            strokeWidth: bind 0.008 * currentHeight
            arcWidth: bind 0.01 * currentWidth
            arcHeight: bind 0.01 * currentWidth
        }
        Text {
            font: bind normalFont
            x: bind 0.45 * currentWidth,
            y: bind jFXTVY + (0.05 * currentHeight)
            content: "JavaFX\nTV"
        }
    ]
    onMouseClicked: function( e: MouseEvent ):Void {
        if(saE)
        thirdAnim();
    }
};

var jNameOpacity: Float = 0;
var jName = Group{
    opacity: bind jNameOpacity
    content: [
        Text {
            font: bind normalFont
            x: bind 0.3 * currentWidth,
            y: bind 0.5 * currentHeight
            content: "Dziękuję za uwagę\nZapraszam 14 kwietnia do Warszawy"
        }
    ]
}
var s: Group= Group{
    content: [
        jApplet
        jMe
        jMf
        jFx
        jFXDesktop
        jFXMobile
        jFXTV
        jName
    ]
};

var slide: Group = Group{
    content: [
        titleBar
        s
        timer
    ]
    onMouseClicked: function( e: MouseEvent ):Void {
        timer.play();
    }
}


var stage: Stage = Stage {
    title: "JavaFX w dokładnie 5 minut"
    fullScreen: true
    style: StageStyle.UNDECORATED
    width: 800
    height: 600
    scene: Scene {
        content: [
            slide
        ]
    }
}